package com.deu.tsf.common.api;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description: 动态API 配置
 * @author Y.Jin
 * @date 2016年12月16日 上午11:43:38
 */
@EnableWebMvc
@EnableSwagger2
@ComponentScan(basePackages = {"com.deu.tsf.controller"})
@Configuration
public class RestApiConfig extends WebMvcConfigurationSupport {

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage("com.deu.tsf.controller")).paths(PathSelectors.any()).build();
	}

	private ApiInfo apiInfo() {
		Contact contact = new Contact("DEU J.Jin", "", "");
		ApiInfo apiInfo = new ApiInfo("TSF土石方管理系统API", // 大标题
				"... api ...", // 小标题
				"0.1", // 版本
				"", contact, // 作者
				"主页", // 链接显示文字
				""// 网站链接
		);
		return apiInfo;
	}
}
